<!DOCTYPE html>
<html lang="en">

<head lang="en">
    <meta charset="UTF-8">
    <title>小鹅拼拼 - 登录</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>

    <link rel="shortcut icon" href="img/xiaoe.ico"/>

    <link rel="stylesheet" href="AmazeUI-2.4.2/assets/css/amazeui.css"/>
    <link href="css/dlstyle.css" rel="stylesheet" type="text/css">
    <!--    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.9/dist/vue.js"></script>-->
    <!--    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>-->
    <script src="js/vue.js"></script>
    <script src="js/axios.min.js"></script>
</head>

<body>

<div class="login-boxtitle">
    <a href="index.html"><img alt="logo" src="images/logobig.png"/></a>
</div>

<div class="login-banner" id="login">
    <div class="login-main">
        <div class="login-banner-bg"><span></span><img src="img/loginpage.png" alt=""/></div>
        <div class="login-box">

            <h3 class="title">登录商城</h3>
            <div class="clear"></div>
            <div class="login-form">
                <form>
                    <div class="user-name">
                        <label for="user"><i class="am-icon-user"></i></label>
                        <input type="text" v-model="username" id="user" placeholder="请输入用户名">
                    </div>
                    <div class="user-pass">
                        <label for="password"><i class="am-icon-lock"></i></label>
                        <input type="password" v-model="password" id="password" placeholder="请输入密码">
                    </div>
                </form>
            </div>

            <div class="login-links">
                <a :href="'register.html?returnUrl=' + returnUrl" class="am-fr">前往注册</a>
                <br/>
            </div>
            <div class="am-cf">
                <input type="button" name="" value="登 录" @click="doLogin" class="am-btn am-btn-primary am-btn-sm">
            </div>
        </div>
    </div>
</div>

<div class="footer ">
    <div class="footer-bd ">
        <p>
            <em>© 2021 pinpin.com 粤ICP备13009803号-11 深圳小鹅文化传媒有限公司 版权所有</em>
        </p>
    </div>
</div>
<script type="text/javascript " src="js/app.js"></script>
<script type="text/javascript">
	const index = new Vue({
		el: "#login",
		data: {
			username: null,
			password: null,

			returnUrl: ""
		},
		created() {

			// 登录成功后会跳原来页面
			let returnUrl = app.getUrlParam("returnUrl");
			if (returnUrl !== null && returnUrl !== undefined && returnUrl !== '') {
				this.returnUrl = returnUrl;
			}
		},
		methods: {
			getRequest() {
			},
			postRequest() {
			},
			doLogin() {

				if (this.username === null || this.username === undefined || this.username === '') {
					alert("用户名不能为空");
					return;
				} else if (this.password === null || this.password === undefined || this.password === '') {
					alert("密码不能为空");
					return;
				} else if (this.password.length < 6) {
					alert("密码不能少于6位");
					return;
				}

				let userBO = {
					username: this.username,
					password: this.password
				};
				// console.log(userBO);

				let serverUrl = app.serverUrl;

				let returnUrl = this.returnUrl;
				// form提交
				axios.defaults.withCredentials = true;
				// console.log(axios.defaults);
				axios.post(serverUrl + '/passport/login', userBO)
						.then(res => {
							if (res.data.status === 200) {
								let user = res.data;
								if (returnUrl !== null && returnUrl !== undefined && returnUrl !== '') {
									window.location.href = returnUrl;
								} else {
									window.location.href = "index.html";
								}
							} else if (res.data.status === 500) {
								alert(res.data.msg);
							}
						});
			}
		}
	});
</script>
</body>

</html>
